#ifndef MAPPARSER_H
#define MAPPARSER_H

#include <QString>

#include "../opxml/rwxml.h"
#include "commondefine.h"

class MapParser
{
public:
    MapParser();
    ~MapParser();

    // 解析xml基本信息
    bool loadMapFromFile(const std::string &strMapFileName);

    int parseHeader(const TiXmlElement &xmlNode, Header &header, bool &bNewVersion);
    int parseRoad(const TiXmlElement &xmlNode, QVector<SRoad> &vecRoads);
    int parseController(const TiXmlElement &xmlNode, QVector<SController> &vecController);
    int parserJunction(const TiXmlElement &xmlNode, QVector<Junction> &vecJunction);

    // 解析Road基本信息
    int parseRoadLink(const TiXmlElement &xmlNode, RoadLink &roadLink);
    int parseRoadType(const TiXmlElement &xmlNode, RoadType &roadType);
    int parsePlanView(const TiXmlElement &xmlNode, PlanView &planView);
    int parseElevationProfile(const TiXmlElement &xmlNode, ElevationProfile &elevationProfile);
    int parseRoadLanes(const TiXmlElement &xmlNode, Lanes &lanes);
    int parseRoadObjects(const TiXmlElement &xmlNode, Objects &objects);
    int parseRoadSignals(const TiXmlElement &xmlNode, Signals &roadSignals);

private:
    int getLongitudeZone(double dLongitude);
    bool bRoadBelongToJunction(const std::string &strRoadID);

    int parseRoadLinkRelat(const TiXmlElement &xmlNode, LinkParameter &relat);
    int parseGeometry(const TiXmlElement &xmlNode, QVector<SGeometry> &vecGeometry);
    int parseElevation(const TiXmlElement &xmlNode, QVector<SElevation> &vecElevation);
    int parseLaneOffset(const TiXmlElement &xmlNode, QVector<SLaneOffset> &vecLaneOffset);
    int parseLaneLink(const TiXmlElement &xmlNode, LaneLink &laneLink);
    int parseLane(const TiXmlElement &xmlNode, QVector<SLane> &vecLane);
    int parseLaneSection(const TiXmlElement &xmlNode, QVector<SLaneSection> &vecLaneSection);
    int parseObject(const TiXmlElement &xmlNode, QVector<Object> &vecObject);
    int parseSignal(const TiXmlElement &xmlNode, QVector<Signal> &vecSignal);
    int parseControl(const TiXmlElement &xmlNode, QVector<Control> &vecControl);
    int parseConnectLaneLink(const TiXmlElement &xmlNode, QVector<ConnectLaneLink> &vecConnectLaneLink);
    int parseConnection(const TiXmlElement &xmlNode, QVector<Connection> &vecConnection);
    int parseJunctionController(const TiXmlElement &xmlNode, QVector<JunctionController> &vecController);

private:
    QString m_qstrRoadPath;
    RwXml *m_pRwXml;
};

#endif // MAPPARSER_H
